
// src/pages/CreateVM/Step2Resources.tsx
import React from 'react';
import { Form, InputNumber, Slider } from 'antd';
import { VMConfig } from './CreateVMWizard';

interface Step2Props {
  config: VMConfig;
  updateConfig: (updates: Partial<VMConfig>) => void;
}

const Step2Resources: React.FC<Step2Props> = ({ config, updateConfig }) => {
  return (
    <Form layout="vertical">
      <Form.Item label="CPU 核心数" required>
        <Slider
          min={1}
          max={16}
          value={config.vcpus}
          onChange={(value) => updateConfig({ vcpus: value })}
          marks={{
            1: '1',
            4: '4',
            8: '8',
            16: '16',
          }}
        />
        <InputNumber
          min={1}
          max={32}
          value={config.vcpus}
          onChange={(value) => updateConfig({ vcpus: value || 2 })}
          style={{ marginTop: '8px' }}
        />
      </Form.Item>

      <Form.Item label="内存 (MB)" required>
        <Slider
          min={512}
          max={32768}
          step={512}
          value={config.memory}
          onChange={(value) => updateConfig({ memory: value })}
          marks={{
            512: '512MB',
            2048: '2GB',
            8192: '8GB',
            16384: '16GB',
            32768: '32GB',
          }}
        />
        <InputNumber
          min={512}
          max={65536}
          value={config.memory}
          onChange={(value) => updateConfig({ memory: value || 2048 })}
          style={{ marginTop: '8px' }}
          addonAfter="MB"
        />
      </Form.Item>

      <Form.Item label="最大内存 (MB)">
        <InputNumber
          min={config.memory}
          max={65536}
          value={config.maxMemory}
          onChange={(value) => updateConfig({ maxMemory: value || config.memory })}
          addonAfter="MB"
        />
      </Form.Item>
    </Form>
  );
};

export default Step2Resources;